import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import router from '@/router'
import useToken from '@/stores/token.js'


// 路由白名单
const writeList = ['/login','/404']

// 全局前置守卫
router.beforeEach((to, from, next)=>{
    const {token} = useToken()
    nprogress.start()
    if(token){
        console.log(token)
        if(to.path==='/login'){
            next('/')
        }else{
            next()
        }
    }else{
        console.log(111)
        if(writeList.includes(to.path)){
            next()
        }else{
            next('/login')
        }
    }
})

// 全局后置守卫
router.afterEach(()=>nprogress.done())